package com.dnndo.common.utils.oss;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * 项目启动时初始化oss
 */
@Configuration
@Log4j2
public class OssConfig {
    @Value("${sky.alioss.endpoint}")
    private String endpoint;

    @Value("${sky.alioss.access-key-id}")
    private String accessKeyId;

    @Value("${sky.alioss.access-key-secret}")
    private String accessKeySecret;

    @PostConstruct
    public void initOssClient() {
        OssClientHolder.init(endpoint, accessKeyId, accessKeySecret);
        log.info("初始化阿里云OSS客户端成功");
    }

    @PreDestroy
    public void destroyOssClient() {
        OssClientHolder.shutdown();
    }
}
